<template>
  <div class="container">
    <div
      v-for="(item, index) in list"
      :key="index"
      class="comment-cell with-grey-bottom-border"
    >
      <div class="avatar">
        <img :src="item.avatar" alt="" />
      </div>
      <div class="comment">
        <div class="top-text">
          <span class="username">{{ item.nickname }}</span> 评论了你的动态
        </div>
        <div class="comment-content">
          {{ item.describe }}
        </div>
        <div class="time">
          {{ item.created_at }} 
          <!-- <span class="reply">回复</span> -->
        </div>
      </div>
      <div class="dynamics-img">
        <img :src="item.map" alt="" />
      </div>
    </div>
    <loadMore @loadMore="loadMore"></loadMore>
  </div>
</template>

<script>
import loadMore from "@/components/load-more";
import { getCommentMsg } from "@/api/msg-center";
export default {
  data() {
    return {
      list: [],
      page: 1,
      loading: false,
      isAll: false
    };
  },
  methods: {
    loadMore() {
      if (this.loading || this.isAll || this.list.length === 0) return;
      this.loading = true;
      this.getCommentMsg(++this.page);
    },
    getCommentMsg(page) {
      getCommentMsg({ page }).then(res => {
        if (res.status === 200) {
          this.list.push(...res.data.data);
          if (res.data.data.length === 0) {
            this.isAll = true;
            this.$dialog.toast({
              mes: "已经到最底了",
              timeout: 1500
            });
          }
        }
        this.$nextTick(() => {
          this.loading = false;
        });
      });
    }
  },
  created() {
    this.getCommentMsg(1);
  },
  components: {
    loadMore
  }
};
</script>

<style lang="less" scoped>
.container {
  padding-bottom: 1rem;
  .comment-cell {
    display: flex;
    justify-content: space-between;
    padding: 0.48rem 3.2%;
    background: #fff;

    .avatar {
      width: 1.8rem;
      height: 1.8rem;
      border-radius: 50%;
      background: #dfdfdf;
      margin-right: 0.48rem;
      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
    }

    .comment {
      width: calc(100% - 3.76rem);
      font-size: 0.56rem;

      .top-text {
        color: #444444;

        .username {
          font-weight: bold;
        }
      }

      .comment-content {
        color: #666666;
        margin: 0.3rem 0;
      }

      .time {
        color: #999999;
        font-size: 0.48rem;

        .reply {
          color: #0084ff;
          margin-left: 1rem;
        }
      }
    }

    .dynamics-img {
      height: 2rem;
      width: 2rem;
      margin-left: 0.48rem;
      background: #dfdfdf;
      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
    }
  }
}
</style>
